package com.bbs.web.validate.utils;

import org.apache.commons.lang.StringUtils;

import com.bbs.model.Person;
import com.bbs.utils.ValidatePropertiesUtils;
import com.bbs.web.utils.PropertiesKey;

/**
 * 用户信息验证
 * @author piggsoft
 * @e-mail piggsoft@163.com
 * @since 2013-4-13
 * @version 1.0
 */
public class PersonValidate{
	public static void validate(Person person){
		validateUsername(person.getUsername());
	}
	
	public static void validateUsername(String username) {
		if (StringUtils.isEmpty(username)) {
			throw new ValidateException("the username of person can not be empty");
		}
		if (!username.matches(ValidatePropertiesUtils.get(PropertiesKey.VALIDATE_PERSON_USERNAME))) {
			throw new ValidateException("the username of person's format is not correct");
		}
	}
	
	public static void main(String[] args) {
		Person person = new Person();
		person.setUsername("!@aaaaaa");
		validate(person);
	}
}
